package com.wn.comment.controller;

import com.github.pagehelper.PageInfo;
import com.wn.comment.common.DataGridResponse;
import com.wn.comment.service.CommentService;
import com.wn.comment.vo.CarPortOrCommentVO;
import com.wn.common.entity.Const;
import com.wn.common.entity.MyParam;
import com.wn.common.entity.MyRsp;
import com.wn.common.pojo.CarPort;
import com.wn.common.pojo.Comment;
import com.wn.common.pojo.Orders;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @BelongsProject: shared_parking
 * @BelongsPackage: com.wn.comment.controller
 * @Author: 徐俊柯
 * @CreateTime: 2020-06-11 14:47
 * @Description:
 */
@Api(description = "评价管理")
@Slf4j
@RestController
public class CommentController {

    @Autowired
    CommentService commentService;

    /*
     * 查询评价信息
     */
    //查询所有评价(分页查询)
    @ApiOperation("查询所有的评价 支持分页和排序")
    @PostMapping("/getCommentAll")
    public MyRsp getCommentAll(@RequestBody MyParam<Comment> myParam){
        PageInfo<Comment> all = commentService.getCommentAll(myParam);
        return MyRsp.success(all);
    }
    //高级检索
    @ApiOperation("按照关键字高级检索 支持分页和排序")
    @PostMapping("/superSearch")
    public MyRsp superSearch(@RequestBody MyParam<Comment> myParam){
        PageInfo<Comment> all = commentService.getCommentAll(myParam);
        return MyRsp.success(all);
    }

    /*
    *   后台系统管理的平台方查询出所有评价（分页）和模糊查询
    */
    @ApiOperation("后台系统管理的平台方查询出所有评价（分页）和模糊查询")
    @PostMapping("/commentList")
    public DataGridResponse commentList(Integer page,Integer rows,String coRtostate){
        DataGridResponse comments = commentService.getCommentList(page, rows,coRtostate);
        return comments;
    }


    /*
     *添加一条评价
     *
     * @RequestBody 作用：将前端穿过来的json数据 映射成实体类  后台要用实体类来接收前端参数
     */
    @ApiOperation("添加一条评价信息")
    @PostMapping("/addComment")
    public MyRsp addComment(String name,String subtitle,String price){

        Integer integer = commentService.addOne(name,subtitle,price);
        if (integer > 0){
            return MyRsp.success1(Const.Status.STATUS_SUCCESS,"添加成功");
        }else{
            return MyRsp.success1(Const.Status.STATUS_ERROR,"添加失败");
        }
}

    /*
     * 删除
     */
    //1.物理删除
    @ApiOperation("物理删除一条评价")
    @PostMapping("/deleteOneTrueById")
    public MyRsp deleteOneTrueById(@RequestBody String coId) {
        Integer integer = commentService.deleteOneTrueById(coId);
        if (integer > 0){
            return MyRsp.success1(Const.Status.STATUS_SUCCESS,"删除成功");
        }else {
            return MyRsp.success1(Const.Status.STATUS_ERROR,"删除失败");
        }
    }
    //2.逻辑删除
    @ApiOperation("逻辑删除一条评价")
    @PostMapping("/deleteOneLogicalById")
    public MyRsp deleteOneLogicalById(@RequestBody Comment comment) {
        Integer integer = commentService.deleteOneLogicalById(comment.getCoId());
        if (integer > 0){
            return MyRsp.success1(Const.Status.STATUS_SUCCESS,"删除成功");
        }else {
            return MyRsp.success1(Const.Status.STATUS_ERROR,"删除失败");
        }
    }
    //3.恢复一个被逻辑删除的评价
    @ApiOperation("恢复一个被逻辑删除的评价")
    @PostMapping("/recoverOneById")
    public MyRsp recoverOneById(@RequestBody String coId) {
        Integer integer = commentService.recoverOneById(coId);
        if (integer > 0){
            return MyRsp.success1(Const.Status.STATUS_SUCCESS,"恢复成功");
        }else {
            return MyRsp.success1(Const.Status.STATUS_ERROR,"恢复失败");
        }
    }
    /*
     * 批量删除
     */
    @ApiOperation("批量删除")
    @PostMapping("/deleteSomeByIds")
    public MyRsp deleteSomeByIds(@RequestBody String[] coIds){

        System.out.println(coIds+"/////////////////////");

        Integer integer = commentService.deleteSomeByIds(coIds);
        if (integer > 0){
            return MyRsp.success1(Const.Status.STATUS_SUCCESS,"删除成功");
        }else {
            return MyRsp.success1(Const.Status.STATUS_ERROR,"删除失败");
        }
    }

    /*
     * 手机端前台 根据车位ID查询出订单ID
     * 手机端前台 根据车位ID查询出的车位信息
     */
    @ApiOperation("手机端前台 根据车位ID查询出订单ID或者手机端前台 根据车位ID查询出的车位信息")
    @PostMapping("/cpIdGetOrderId")
    public MyRsp cpIdGetOrderId(@RequestBody CarPort carPort){
        List<CarPort> result = commentService.cpIdGetOrderId(carPort.getCpId());
        return MyRsp.success(result);
    }

    /*
     * 手机端前台 根据订单ID查看评价
     */
    @ApiOperation("手机端前台 根据订单ID查看评价")
    @PostMapping("/getPhoneCommentAll")
    public MyRsp getPhoneCommentAll(@RequestBody CarPortOrCommentVO carPortOrCommentVO){
        List<CarPortOrCommentVO> phoneCommentAll = commentService.getPhoneCommentAll(carPortOrCommentVO.getOId());
        return MyRsp.success(phoneCommentAll);
    }

    /**
     * 添加：根据前端传递过来的用户名称查询出用户的订单ID
     */
    @ApiOperation("根据前端传递过来的用户名获取订单信息")
    @PostMapping("/getOrderInfo")
    public MyRsp getOrderInfo(String userName){
        List<Orders> orderId = commentService.getOrderId(userName);
        return MyRsp.success(orderId);
    }


    /*
     * 手机端前台 根据订单ID进行添加评价
     */
    @ApiOperation("手机端前台 添加评价")
    @PostMapping("/addPhoneComment")
    public MyRsp addPhoneComment(String oId,String commentName,String coRtostate,String coT){

        System.out.println(oId+"///////////////////"+oId);

        Integer integer = commentService.addPhoneComment(oId,commentName, coRtostate, coT);
        if (integer > 0){
            return MyRsp.success1(Const.Status.STATUS_SUCCESS,"添加成功");
        }else {
            return MyRsp.success1(Const.Status.STATUS_ERROR,"添加失败");
        }
    }





}
